﻿
Imports System.IO
Imports System.Net
Imports System.Runtime.CompilerServices
Imports osi.root.formation

Public Module _webrequest
    <Extension()> Public Function get_response(ByVal w As WebRequest,
                                               ByVal r As pointer(Of WebResponse)) As event_comb
        Return create(Function() As Boolean
                          Return Not w Is Nothing AndAlso Not r Is Nothing
                      End Function,
                      Function() As event_comb
                          Return event_comb_async_operation.ctor(
                                        Function(ac As AsyncCallback) As IAsyncResult
                                            Return w.BeginGetResponse(ac, Nothing)
                                        End Function,
                                        Function(ar As IAsyncResult) As WebResponse
                                            Return w.EndGetResponse(ar)
                                        End Function,
                                        r)
                      End Function)
    End Function

    <Extension()> Public Function get_request_stream(ByVal w As WebRequest,
                                                     ByVal r As pointer(Of Stream)) As event_comb
        Return create(Function() As Boolean
                          Return Not w Is Nothing AndAlso Not r Is Nothing
                      End Function,
                      Function() As event_comb
                          Return event_comb_async_operation.ctor(
                                        Function(ac As AsyncCallback) As IAsyncResult
                                            Return w.BeginGetRequestStream(ac, Nothing)
                                        End Function,
                                        Function(ar As IAsyncResult) As Stream
                                            Return w.EndGetRequestStream(ar)
                                        End Function,
                                        r)
                      End Function)
    End Function
End Module
